package cn.libinal.scloud.base.common.entity;

import cn.libinal.scloud.base.common.utils.SnowflakeIdWorker;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGenerator;

import java.io.Serializable;

/**
 * 自定义ID生成策略
 * @author libin
 */
public class SnowflakeId implements IdentifierGenerator {
    @Override
    public Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException {
        SnowflakeIdWorker worker = SnowflakeIdWorker.getInstance();
        return worker.nextId() + "";
    }
}
